/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import com.jnetx.javax.sip.address.HttpURIImpl;
import junit.framework.TestCase;

import java.text.ParseException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class AlertInfoHeaderParserTest extends TestCase {
    public AlertInfoHeaderParserTest(String name) {
        super(name);
    }

    public void test() {
        final byte[] data = "Alert-Info: <http://www.example.com/sounds/moo.wav>;priority=high, <http://www.example.com/sounds/foo.mp3>;importance=low".getBytes();
        final AlertInfoHeaderParser parser = new AlertInfoHeaderParser();
        AlertInfoHeaderImpl[] headers;
        try {
            headers = parser.parse(data, 11, data.length);
        } catch (ParseException e) {
            fail(e.getMessage());
            return;
        }
        assertNotNull("The result is null!", headers);
        assertEquals("The length of the result is wrong!", 2, headers.length);
        final HttpURIImpl uri1 = new HttpURIImpl();
        uri1.setHost("http://www.example.com");
        uri1.setPath("/sounds/moo.wav");
        final HttpURIImpl uri2 = new HttpURIImpl();
        uri1.setHost("http://www.example.com");
        uri1.setPath("/sounds/foo.mp3");
        assertEquals("The uri is wrong!", uri1, headers[0].getAlertInfo());
        assertEquals("The priority is wrong!", "high", headers[0].getParameter("priority"));
        assertEquals("The string representation is wrong!", "Alert-Info: <http://www.example.com/sounds/moo.wav>;priority=high", headers[0].toString());
        assertEquals("The uri is wrong!", uri2, headers[1].getAlertInfo());
        assertEquals("The importance is wrong!", "low", headers[1].getParameter("importance"));
        assertEquals("The string representation is wrong!", "Alert-Info: <http://www.example.com/sounds/foo.mp3>;importance=low", headers[1].toString());
    }
}
/*
 * $Log$
 */